home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / diskproc / readLocalDisk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  4.6 KB  |  163 lines

  1. /*
  2.  *   $RCSfile: readLocalDisk.c,v $  
  3.  *   $Revision: 1.2 $  
  4.  *   $Date: 1996/05/04 23:51:47 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37. #include "sysdefs.h"
  38. #include <sys/file.h>
  39. #include "ess.h"
  40. #include "checking.h"
  41. #include "trace.h"
  42. #include "error.h"
  43. #include "list.h"
  44. #include "tid.h"
  45. #include "io.h"
  46. #include "lock.h"
  47. #include "object.h"
  48. #include "msgdefs.h"
  49. #include "disk.h"
  50. #include "queues.h"
  51. #include "diskproc_globals.h"
  52. #include "diskproc_intfuncs.h"
  53. #include "diskproc_extfuncs.h"
  54.  
  55. extern char        *ShmAddress;
  56. extern int        Fd;
  57.  
  58. #ifdef DISKPROC_MAKE
  59. /* see comments below where Shmstruct is used. */
  60. extern struct shmid_ds Shmstruct;
  61. #endif DISKPROC_MAKE
  62.  
  63.  void
  64. readLocalDisk (
  65.  
  66.     register DISKMSG    *message
  67. )
  68. {
  69.  
  70.     int        length;
  71.     int        readLength;
  72.     struct    iovec    ioPageVec[MAX_DISK_IOVEC];
  73.     int        i;
  74.  
  75.     SM_ASSERT(LEVEL_1, (Fd != fileno(stdin)));
  76.  
  77.     TRPRINT(TR_DISKRW, TR_LEVEL_1, ("reading at:%d numVectors:%d",
  78.             message->body.offset, message->body.diskVecCount));
  79.  
  80.     /*
  81.      *    attempt to seek to the place in the file
  82.      */
  83.     if (lseek(Fd, (int) message->body.offset, L_SET) < 0)    {
  84.  
  85.         /*
  86.          *    print an error message
  87.          */
  88.         SM_ERROR(TYPE_SYS, errno);
  89.  
  90.         /*
  91.          *    reply in the negative
  92.          */
  93.         if (errno == 0) SM_ERROR(TYPE_FATAL, esmINTERNAL);
  94.         message->header.params.out.errno = errno;
  95.         message->diskmagic = DISK_MESSAGE_MAGIC;
  96.         replyDiskMessage(message);
  97.     }
  98.  
  99.     /*
  100.      *    Generate the io vec for the read 
  101.      */
  102.     SM_ASSERT(LEVEL_3, (message->body.diskVecCount > 0) && 
  103.                        (message->body.diskVecCount <= MAX_DISK_IOVEC));
  104.     length = 0;
  105.     for (i = 0; i < message->body.diskVecCount; i++) {
  106.  
  107. #    ifdef DISKPROC_MAKE
  108.         /* Include this check only for the disk process because
  109.          * Shmstruct doesn't exist in the server process.  The check
  110.          * is unnecessary in the single process case anyway.
  111.          */
  112. #    if defined(mips) || defined (vax)
  113.         SM_ASSERT(LEVEL_3, ((message->body.diskVec[i].bufIndex < Shmstruct.sm_size) && (message->body.diskVec[i].bufIndex >= 0)) );
  114. #    elif defined(sparc) || defined(_AIX) || defined(hpux) || defined(linux)
  115.         SM_ASSERT(LEVEL_3, ((message->body.diskVec[i].bufIndex < Shmstruct.shm_segsz) && (message->body.diskVec[i].bufIndex >= 0)) );
  116. #    elif !(defined(sparc) || defined(mips) || defined(vax) || defined(_AIX) || defined(hpux) || defined(linux))
  117.         unsupported
  118. #    else
  119.         /* can't put the else part here because ultrix cpp is broken */
  120. #    endif
  121. #    endif DISKPROC_MAKE
  122.  
  123.         ioPageVec[i].iov_base = ShmAddress+(int)message->body.diskVec[i].bufIndex;
  124.         ioPageVec[i].iov_len = (int)message->body.diskVec[i].length;
  125.  
  126.         /* pull the length out of the message */
  127.         length += (int)message->body.diskVec[i].length;
  128.  
  129.     }
  130.  
  131.     /*
  132.      *    attempt to read the vector from the disk
  133.      */
  134.     errno = 0;
  135.     if ((readLength = readv(Fd, ioPageVec, message->body.diskVecCount)) < length)    {
  136.  
  137.         /*
  138.          *    print an error message
  139.          */
  140.         if(errno)
  141.             SM_ERROR(TYPE_SYS, errno);
  142.  
  143.         /*
  144.          *    reply in the negative
  145.          */
  146.         if (errno == 0) SM_ERROR(TYPE_FATAL, esmINTERNAL);
  147.         message->header.params.out.errno = errno;
  148.         message->diskmagic = DISK_MESSAGE_MAGIC;
  149.         replyDiskMessage(message);
  150.  
  151.     } else {
  152.  
  153.         TRPRINT(TR_DISKRW, TR_LEVEL_2, ("read successful:%d bytes", length));
  154.  
  155.         /*
  156.          *    reply in the positive
  157.          */
  158.         message->header.params.out.errno = esmNOERROR;
  159.         message->diskmagic = DISK_MESSAGE_MAGIC;
  160.         replyDiskMessage(message);
  161.     }
  162. }
  163.